package com.mmall.common;

import com.mmall.utils.PropertiesUtil;
import lombok.extern.slf4j.Slf4j;
import org.redisson.Redisson;
import org.redisson.config.Config;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
@Slf4j
public class RedissonManager {

    private Config config = new Config();

    private Redisson redisson = null;

    private static String ip1 = PropertiesUtil.getProperty("redis1.ip");

    private static Integer port1 = Integer.parseInt(PropertiesUtil.getProperty("redis1.port"));

    private static String ip2 = PropertiesUtil.getProperty("redis2.ip");

    private static Integer port2 = Integer.parseInt(PropertiesUtil.getProperty("redis2.port"));


    /**
     * 初始化方法，
     */
    @PostConstruct
    private void init() {
        try {

            //单服务初始化,默认时master服务
            config.useSingleServer().setAddress(PropertiesUtil.getProperty("redisson.address"));

            redisson = (Redisson) Redisson.create(config);

            log.info("redisson init end 初始化结束");
        } catch (Exception e) {
            log.error("redisson itit error 初始化异常",e);
            e.printStackTrace();
        }

    }

    public Redisson getRedisson() {
        return redisson;
    }
}
